#ifndef __TCPLIB_H_
#define __TCPLIB_H_
#include <string>
class TcpServer
{
public:
    /*构造函数*/
    TcpServer(const std::string &ip = "0,0,0,0", int port = 8888) : m_ip(ip), m_port(port)
    {
    }
    // /*拷贝构造函数*/
    // TcpServer(const TcpServer &server)
    // {
    //     m_ip = server.m_ip;
    //     m_port = server.m_port;
    // }
    // /*析构函数*/
    // ~TcpServer()
    // {
    // }
    /*初始化服务器*/
    bool tcpServerInit();
    /*连接*/
    bool tcpServerAccept();
    /*读取*/
    std::string tcpServerRead();
    /*发送*/
    bool tcpServerWrite(const std::string &sendMessage);
    /*销毁*/
    bool tcpServerDestroy();

private:
    std::string m_ip;
    int m_port;
    int m_acceptfd;
    int m_sockfd;
};

class TcpClient
{
public:
    static TcpClient *instance()
    {
        static TcpClient client;
        return &client;
    }
    // /*拷贝构造函数*/
    // TcpClient(const TcpClient &client)
    // {
    //     m_ip = client.m_ip;
    //     m_port = client.m_port;
    // }
    // /*析构函数*/
    // ~TcpClient()
    // {
    // }
    /*初始化客户端*/
    bool TcpClientInit();
    /*读取*/
    std::string TcpClientRead();
    /*发送*/
    bool TcpClientWrite(const std::string &sendMessage);
    /*销毁*/
    bool TcpClientDestroy();

private:
    /*构造函数*/
    TcpClient(const std::string &ip, int port) : m_ip(ip), m_port(port)
    {
    }
    std::string m_ip;
    int m_port;
    int m_sockfd;
};
#endif